'use strict';

const express = require('express');
const _ = require('lodash');
const router = express.Router();
const { common } = require('./common');

router.post('/saveRolePermission', function(req, res) {
  res.type('json');
  let params = req.body,
    ret = {};

  console.log('roldId', params.roldId);
  console.log('menuIds', params.menuIds);

  Object.assign(ret, common);

  res.send(ret);
});

router.get('/searchRole', function(req, res) {
  res.type('json');
  let params = req.query, ret = {};
  Object.assign(ret, common, {
    data: [{
      key: 1,
      userId: 12,
      name: '管理员000',
      describe: '我是描述',
      cTime: '2017-6-15',
      mTime: '2017-8-15'
    }]
  });
  res.send(ret);
});

router.post('/saveRole', function(req, res) {
  res.type('json');
  let params = req.body,
    ret = {};

  console.log('userName', params.userName);
  console.log('userDescribe', params.userDescribe);

  Object.assign(ret, common, {
    data: {
      roleId: '9999'
    }
  });

  res.send(ret);
});

router.get('/getRoleManagementData', function(req, res) {
  res.type('json');
  let params = req.query,
    ret = {};

  Object.assign(ret, common, {
    data: _.times(25, i => {
      return {
        key: i,
        roleId: 145 + i,
        name: '管理员' + i,
        describe: '我是描述',
        cTime: '2017-6-15',
        mTime: '2017-8-15',
        users: [{
          key: 1,
          userId: 123,
          loginName: '小花',
          name: '糊涂图',
          email: 'tesste111@test.com',
          department: '技术部',
          duty: '工程师',
          role: '开发区',
          oTime: '2017-6-15',
          mTime: '2017-8-15'
        }]
      };
    })
  });

  res.send(ret);
});

router.get("/getSummaryData", function(req, res) {
  res.type("json");
  let params = req.query,
    ret = {};

  Object.assign(ret, common, {
    data: {
      gmv: _.random(0, 1000),
      gmvYOY: _.random(0, 1, true),
      gmvMOM: _.random(0, 1, true),
      uv: _.random(0, 1000),
      uvYOY: _.random(0, 1, true),
      uvMOM: -_.random(0, 1, true),
      uvRates: _.random(0, 1, true),
      uvRatesYOY: _.random(0, 1, true),
      uvRatesMOM: -_.random(0, 1, true),
      userCount: 123132123,
      userCountYOY: _.random(0, 1, true),
      userCountMOM: _.random(0, 1, true)
    }
  });

  res.send(ret);
});

module.exports = router;
